# hive ods import shell
#! /bin/bash
echo "create hive warehouse........... "
if [ $# = 0 ];then
  hive -f init.sql
fi
echo "import product data ............"
# global import product
sqoop import \
	--connect jdbc:mysql://192.168.16.150:3306/sales_source \
	--driver com.mysql.jdbc.Driver \
	--username root \
	--password ok \
	--query "select product_code,product_name,
	product_category,'1.0' as version,'2018-1-1' as ods_start_time,
	'9999-12-31' as ods_end_time from product where \$CONDITIONS" \
	--target-dir /mytmp/ods/op \
	--hive-import \
	--hive-database ods_sales_source \
	--hive-table ods_product \
	--hive-overwrite \
	-m 1;
echo "import customer data ............"
# global import customer
sqoop import \
	--connect jdbc:mysql://192.168.16.150:3306/sales_source \
	--driver com.mysql.jdbc.Driver \
	--username root \
	--password ok \
	--query "select customer_number,customer_name,
	customer_street_address,customer_zip_code,
	customer_city,customer_state,'1.0' as version,'2018-1-1' as ods_start_time,
	'9999-12-31' as ods_end_time from customer where \$CONDITIONS" \
	--target-dir /mytmp/ods/oc \
	--hive-import \
	--hive-database ods_sales_source \
	--hive-table ods_customer \
	--hive-overwrite \
	-m 1;

echo "import sales_order data ............"
sqoop import \
	--connect jdbc:mysql://192.168.16.150:3306/sales_source \
	--driver com.mysql.jdbc.Driver \
	--username root \
	--password ok \
	--query "select order_number,customer_number,product_code,
	order_date,order_amount from sales_order where \$CONDITIONS" \
	--target-dir /mytmp/ods/so \
	--hive-import \
	--hive-database ods_sales_source \
	--hive-table ods_origin_sales_order \
	--hive-overwrite \
	-m 1;

echo "start dynmic partition........"
hive -f dyn.sql
